//
//  MinePersonalDetailBodyCell.swift
//  MT
//
//  Created by M on 2020/1/6.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit
import MTCategory

class MinePersonalDetailBodyCell: UITableViewCell {
    
    var model: MineInfoModel? {
        didSet {
            guard let model = model else { return }
            heightDetailLabel.text = (model.height != nil && model.height! != 0) ? "\(model.height!)cm" : "-"
            weightDetailLabel.text = (model.weight != nil && model.weight! != 0) ? "\(model.weight!)kg" : "-"
            constellationDetailLabel.text = model.constellation ?? "-"
        }
    }
    
    /// 身高 Title
    lazy var heightTitleLabel: UILabel = {
        return createTitleLabel(text: "身高")
    }()
    
    /// 身高 Detail
    lazy var heightDetailLabel: UILabel = {
        return createDetailLabel()
    }()
    
    /// 体重 Title
    lazy var weightTitleLabel: UILabel = {
        return createTitleLabel(text: "体重")
    }()
    
    /// 身高 Detail
    lazy var weightDetailLabel: UILabel = {
        return createDetailLabel()
    }()
    
    /// 星座 Title
    lazy var constellationTitleLabel: UILabel = {
        return createTitleLabel(text: "星座")
    }()
    
    /// 星座 Detail
    lazy var constellationDetailLabel: UILabel = {
        return createDetailLabel()
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        initializeUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

// MARK: ------------------------------------ 初始化 ----------------------------------------
extension MinePersonalDetailBodyCell {
    
    private func initializeUI() {
        selectionStyle = .none
        contentView.backgroundColor = .black
        contentView.addSubview(heightTitleLabel)
        contentView.addSubview(heightDetailLabel)
        contentView.addSubview(weightTitleLabel)
        contentView.addSubview(weightDetailLabel)
        contentView.addSubview(constellationTitleLabel)
        contentView.addSubview(constellationDetailLabel)
        
//        heightTitleLabel.snp.makeConstraints { (make) in
//            make.top.equalTo(contentView).offset(35)
//            make.left.equalTo(contentView).offset(40)
//        }
//
//        weightTitleLabel.snp.makeConstraints { (make) in
//            make.top.equalTo(heightTitleLabel)
//            make.width.equalTo(heightTitleLabel)
//            make.left.equalTo(heightTitleLabel.snp.right).offset(40)
//        }
//
//        constellationTitleLabel.snp.makeConstraints { (make) in
//            make.top.equalTo(heightTitleLabel)
//            make.width.equalTo(heightTitleLabel)
//            make.right.equalTo(contentView).offset(-40)
//            make.left.equalTo(weightTitleLabel.snp.right).offset(40)
//        }
        
        heightTitleLabel.snp.makeConstraints { (make) in
            make.top.equalTo(contentView).offset(35)
            make.left.equalTo(contentView).offset(60)
        }
        
        weightTitleLabel.snp.makeConstraints { (make) in
            make.top.equalTo(heightTitleLabel)
            make.centerX.equalTo(contentView)
//            make.width.equalTo(heightTitleLabel)
//            make.left.equalTo(heightTitleLabel.snp.right).offset(40)
        }
        
        constellationTitleLabel.snp.makeConstraints { (make) in
            make.top.equalTo(heightTitleLabel)
            make.width.equalTo(heightTitleLabel)
            make.right.equalTo(contentView).offset(-60)
//            make.left.equalTo(weightTitleLabel.snp.right).offset(40)
        }
        
        heightDetailLabel.snp.makeConstraints { (make) in
//            make.centerX.width.equalTo(heightTitleLabel)
            make.left.equalTo(heightTitleLabel)
            make.top.equalTo(heightTitleLabel.snp.bottom).offset(8)
        }
        
        weightDetailLabel.snp.makeConstraints { (make) in
//            make.centerX.width.equalTo(weightTitleLabel)
            make.left.equalTo(weightTitleLabel)
            make.top.equalTo(weightTitleLabel.snp.bottom).offset(8)
        }
        
        constellationDetailLabel.snp.makeConstraints { (make) in
//            make.centerX.width.equalTo(constellationTitleLabel)
            make.left.equalTo(constellationTitleLabel)
            make.top.equalTo(constellationTitleLabel.snp.bottom).offset(8)
        }
        
    }
    
}

// MARK: ------------------------------------ 创建控件 ----------------------------------------
extension MinePersonalDetailBodyCell {
    
    private func createTitleLabel(text: String) -> UILabel {
        let label = UILabel()
        label.text = text
        label.textColor = UIColor(hex: 0x5d5d5d)
        label.font = PingFangSCMediumFont(12)
        label.textAlignment = .center
        return label
    }
    
    private func createDetailLabel() -> UILabel {
        let label = UILabel()
        label.text = "-"
        label.textColor = .white
        label.font = PingFangSCMediumFont(14)
        label.textAlignment = .center
        return label
    }
    
}
